Carte du monde

Relations avec des indicateurs

Row

GDP par habitant (USD)

Pourcentage de dépenses en santé en pourcentage du GDP

Row

Pourcentage d’enfants de moins de 5 ans atteints d’anémie

Pourcentage de personnes ayant accès à l’eau potable

Focus sur 3 pays

Row

Syrie

Grenade

Row

Venezuela

---
title: "Quels sont les facteurs qui peuvent influencer l'évolution de l'espérance de vie?"
author: "Amélie Rivet & Sofia Chemolli"
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    social: menu
    source_code: embed
---

<style>                     
.navbar {
background-color:#81C6E8;
border-color:#81C6E8;
}
.navbar-brand {
color:black!important;
}


</style>  

```{r setup, include=FALSE}
library(ggplot2)
library(tidyverse)
library(dplyr)
library(plotly)
library(flexdashboard)
```

Carte du monde 
=======================================================================

```{r data, eval = TRUE, echo = FALSE, results='hide', message = FALSE, warning=FALSE}
# Espérance de vie a la naissance
dta_off <- read.csv("Dta_off.csv", sep=",", stringsAsFactors = T)
dta_off <- dta_off[,3:23]
colnames(dta_off) <- c("Country","ISO3","2000", "2001", "2002","2003", "2004", "2005","2006", "2007", "2008","2009","2010", "2011", "2012","2013", "2014", "2015","2016","2017","2018")

dta_off <- dta_off %>% 
  pivot_longer(c("2000", "2001", "2002","2003", "2004", "2005","2006", "2007", "2008","2009","2010", "2011", "2012","2013", "2014", "2015","2016","2017","2018"))
colnames(dta_off)[3:4] <- c("Year", "Life.expectancy")
dta_off$Year <- as.factor(dta_off$Year)

dta_off <- dta_off[-c(4558:nrow(dta_off)),]


# GDP par habitant
dta_GDP <- read.csv("GDPDataBank.csv", sep=",", stringsAsFactors = T)
dta_GDP <- dta_GDP[,4:23]
colnames(dta_GDP) <- c("ISO3","2000", "2001", "2002","2003", "2004", "2005","2006", "2007", "2008","2009","2010", "2011", "2012","2013", "2014", "2015","2016","2017","2018")

dta_GDP <- dta_GDP %>% 
  pivot_longer(c("2000", "2001", "2002","2003", "2004", "2005","2006", "2007", "2008","2009","2010", "2011", "2012","2013", "2014", "2015","2016","2017","2018"))
colnames(dta_GDP)[2:3] <- c("Year", "GDP")
dta_GDP$Year <- as.factor(dta_GDP$Year)


# Dépenses sante % GDP
dta_dep <- read.csv("HealthExpDataBank.csv", sep=",", stringsAsFactors = T)
dta_dep <- dta_dep[,4:23]
colnames(dta_dep) <- c("ISO3","2000", "2001", "2002","2003", "2004", "2005","2006", "2007", "2008","2009","2010", "2011", "2012","2013", "2014", "2015","2016","2017","2018")

dta_dep <- dta_dep %>% 
  pivot_longer(c("2000", "2001", "2002","2003", "2004", "2005","2006", "2007", "2008","2009","2010", "2011", "2012","2013", "2014", "2015","2016","2017","2018"))
colnames(dta_dep)[2:3] <- c("Year", "Depense")
dta_dep$Year <- as.factor(dta_dep$Year)


# Anemie chez les enfants
dta_anemia <- read.csv("WHO_anemia.csv", sep=';', dec=',', stringsAsFactors = T)
dta_anemia$Year <- as.factor(dta_anemia$Year)


# Acces a l'eau potable
dta_water <- read.csv("WaterDataBank.csv", sep=",", stringsAsFactors = T)
dta_water <- dta_water[,4:23]
colnames(dta_water) <- c("ISO3","2000", "2001", "2002","2003", "2004", "2005","2006", "2007", "2008","2009","2010", "2011", "2012","2013", "2014", "2015", "2016","2017","2018")

dta_water <- dta_water %>% 
  pivot_longer(c("2000", "2001", "2002","2003", "2004", "2005","2006", "2007", "2008","2009","2010", "2011", "2012","2013", "2014", "2015", "2016","2017","2018"))
colnames(dta_water)[2:3] <- c("Year", "Water")
dta_water$Year <- as.factor(dta_water$Year)

dta <- left_join(dta_off, dta_dep, by = c("ISO3","Year"))

dta <- left_join(dta, dta_GDP, by = c("ISO3","Year"))

dta <- left_join(dta, dta_anemia[,-2], by = c("ISO3","Year"))

dta <- left_join(dta, dta_water, by = c("ISO3","Year"))

# Amélie
dta.diff <- dta %>% 
  group_by(ISO3) %>%
  summarise(Life.expectancy.diff = Life.expectancy[Year=='2018'] - Life.expectancy[Year=='2000'], 
            Depense.diff = Depense[Year=='2018'] - Depense[Year=='2000'], 
            GDP.diff = GDP[Year=='2018'] - GDP[Year=='2000'],
            Anemie.diff = Anemie[Year=='2018'] - Anemie[Year=='2000'], 
            Water.diff = Water[Year=='2018'] - Water[Year=='2000']) %>%
  arrange(Life.expectancy.diff)

# Sofia
diff.ISO3 <- dta_off %>% 
  filter(Year==2000 | Year==2018) %>% 
  group_by(ISO3) %>%
  summarise(Life.expectancy.diff = Life.expectancy[Year=='2018'] - Life.expectancy[Year=='2000'],
            Country = Country,
            Life.expectancy.2000 = Life.expectancy[Year=='2000'],
            Life.expectancy.2018 = Life.expectancy[Year=='2018']) %>% 
  arrange(Life.expectancy.diff) 
```

```{r vis1,  echo = FALSE,  message = FALSE, warning=FALSE}
fig <- plot_ly(diff.ISO3, 
               
               type = 'choropleth', 
               
               locations = diff.ISO3$ISO3, 
               
               z = diff.ISO3$Life.expectancy.diff, 
               
               text = paste("Pays : ", diff.ISO3$Country, '<br>', 
                            "Esperance de vie en 2000 : ", round(diff.ISO3$Life.expectancy.2000,1), '<br>', 
                            "Esperance de vie en 2018 : ", round(diff.ISO3$Life.expectancy.2018,1), '<br>', 
                            "Difference : ", round(diff.ISO3$Life.expectancy.diff,1)), 
               
               colorscale = "YlGnBu",
               
               hoverinfo = 'text')

m <- list(l = 50, r = 50, b = 100, t = 100, pad = 4)

fig %>% 
  
  colorbar(title = list(
    text = paste0("Différence de \nl'espérance de vie \nentre 2018 et 2000"), 
    font = list(size=16)), 
    x = 0.9, y = 0.8, len = 0.6) %>% 
  
  layout(title = list(text = paste0("Différence de l'espérance de vie par pays" , '<br>', '<sup>',  "entre 2018 et 2000"), 
                      font=list(size=22), xanchor = "middle", y=3), 
         margin = m,
         annotations = list(x = 1, y = -0.1, text = "Source: https://data.worldbank.org/",
                            xref='paper', yref='paper', showarrow = F, 
                            xanchor='right', yanchor='auto', xshift=0, yshift=0,
                            font = list(size = 10)))
```


Relations avec des indicateurs
=======================================================================

Row
-----------------------------------------------------------------------


```{r, eval = TRUE, echo = FALSE, results='hide', message = FALSE, warning=FALSE, fig.keep='none'}
expectancy <- inner_join(dta, dta.diff, by='ISO3')

expectancy.2000 <- expectancy %>% 
  filter(Year==2000)

expectancy.2000[,4:13]<-round(expectancy.2000[,4:13],1)
```

### GDP par habitant (USD)

```{r, echo = FALSE,  message = FALSE, warning=FALSE}
g1 <- ggplot(data = expectancy.2000, 
             aes(x = GDP.diff, y = Life.expectancy.diff, 
                 text=paste("Pays : ",Country,
                            "<br>Espérance de vie en 2000 : ", Life.expectancy, 
                            "<br>GDP en 2000 : ", GDP)), 
             na.rm=TRUE) +
  
  geom_point(aes(color=Life.expectancy, size=GDP)) +
  
  scale_color_gradient(low ="#FFFF99",high = "#009933") +
  
  scale_y_continuous(breaks=seq(-10, 20, 5)) +
  
  scale_x_continuous(breaks=seq(-1000, 101000, 25000)) +
  
  geom_vline(xintercept = 0, color="black", size=1) +
  
  geom_hline(yintercept = 0, color="black", size=1) +
  
  # annotate(geom = "text", 
  #          x = 3000, y = 20, 
  #          label = "x = 0",
  #          color="black",
  #          hjust = "left") +
  
  labs(x = "Différence de GDP par habitant en USD \nentre 2018 et 2000",
       y = "Différence d'espérance de vie \nentre 2018 et 2000",
       colour = "Espérance de vie \nen 2000",
       size = "GDP par habitant \n(en USD) en 2000") +
  
  ggtitle("Représentation de la relation entre \nles différences d'espérance de vie et \n du GDP par habitant entre 2018 et 2000") +
  
  theme(plot.title = element_text(face="bold", hjust=0.5, size=12), 
        axis.title.x = element_text(size=11),
        axis.title.y = element_text(size=11),
        panel.background = element_rect(fill = "white"),
        panel.grid.major = element_line(colour = "#CCCCCC"),
        plot.margin = unit(c(0,0,0,0), "cm"))

g1
```


### Pourcentage de dépenses en santé en pourcentage du GDP 

```{r, echo = FALSE,  message = FALSE, warning=FALSE}

g2 <- ggplot(data = expectancy.2000,
             aes(x = Depense.diff, y = Life.expectancy.diff,
                 text = paste("Pays : ", Country,
                              "<br>Espérance de vie en 2000 : ", Life.expectancy,
                              "<br>Dépenses en santé en % GDP en 2000 : ", Depense," %")),
             na.rm=TRUE) +
  
  geom_point(aes(color=Life.expectancy, size=Depense)) +
  
  scale_color_gradient(low ="#FFFF99",high = "#009933") +
  
  scale_y_continuous(breaks=seq(-10, 20, 5)) +
  
  scale_x_continuous(limits=c(-5,7.5), breaks=seq(-5, 7.5, 2.5)) +
  
  geom_vline(xintercept = 0, color="black", size=1) +
  
  geom_hline(yintercept = 0, color="black", size=1) +
  
  # annotate(geom = "text", 
  #          x = 3000, y = 20, 
  #          label = "x = 0",
  #          color="black",
  #          hjust = "left") +
  
  labs(x = "Différence du pourcentage de dépenses \nen santé en pourcentage du GDP \nentre 2018 et 2000",
       y = "Différence d'espérance de vie \nentre 2018 et 2000",
       colour = "Espérance de vie \nen 2000",
       size = "% de dépenses en \nsanté en 2000") +
  
  ggtitle("Représentation de la relation entre \nles différences d'espérance de vie et \n des dépenses en santé entre 2018 et 2000") +
  
  theme(plot.title = element_text(face="bold", hjust=0.5, size=12), 
        axis.title.x = element_text(size=11),
        axis.title.y = element_text(size=11),
        panel.background = element_rect(fill = "white"),
        panel.grid.major = element_line(colour = "#CCCCCC"),
        plot.margin = unit(c(0,0,0,0), "cm")) 

g2

```


Row
-----------------------------------------------------------------------

### Pourcentage d'enfants de moins de 5 ans atteints d'anémie

```{r, echo = FALSE,  message = FALSE, warning=FALSE}
g3 <- ggplot(data = expectancy.2000,
             aes(x = Anemie.diff, y = Life.expectancy.diff,
                 text=paste("Pays : ",Country,
                            "<br>Espérance de vie en 2000 : ", Life.expectancy,
                            "<br> Enfants de moins de 5 ans \natteint d'anémie en 2000 : ", Anemie, "%")),
             na.rm=TRUE) +
  
  geom_point(aes(color=Life.expectancy, size=Anemie)) +
  
  scale_color_gradient(low ="#FFFF99",high = "#009933") +
  
  scale_y_continuous(breaks=seq(-10, 20, 5)) +
  
  scale_x_continuous(limits=c(-30, 5), breaks=seq(-30,5,5))+
  
  geom_vline(xintercept = 0, color="black", size=1) +
  
  geom_hline(yintercept = 0, color="black", size=1) +
  
  # annotate(geom = "text", 
  #          x = 3000, y = 20, 
  #          label = "x = 0",
  #          color="black",
  #          hjust = "left") +
  
  labs(x = "Différence de pourcentage d'enfants de moins \nde 5 ans atteints d'anémie entre 2018 et 2000",
       y = "Différence d'espérance de vie \nentre 2018 et 2000",
       colour = "Espérance de vie \nen 2000",
       size = "% d'enfant atteints \nd'anémie en 2000") +
  
  ggtitle("Représentation de la relation entre \nles différences d'espérance de vie et \n de pourcentage d'enfants de moins de 5 ans \natteints d'anémie entre 2018 et 2000") +
  
  theme(plot.title = element_text(face="bold", hjust=0.5, size=12), 
        axis.title.x = element_text(size=11),
        axis.title.y = element_text(size=11),
        panel.background = element_rect(fill = "white"),
        panel.grid.major = element_line(colour = "#CCCCCC"),
        plot.margin = unit(c(0,0,0,0), "cm"))

g3
```

### Pourcentage de personnes ayant accès à l'eau potable

```{r, echo = FALSE,  message = FALSE, warning=FALSE}
g4 <- ggplot(data = expectancy.2000,
             aes(x = Water.diff, y = Life.expectancy.diff,
                 text=paste("Pays : ",Country,
                            "<br>Espérance de vie en 2000 : ", Life.expectancy,
                            "<br> Accès à l'eau potable en 2000 : ", Water, "%")),
             na.rm=TRUE) +
  
  geom_point(aes(color=Life.expectancy, size=Water)) +
  
  scale_color_gradient(low ="#FFFF99",high = "#009933") +
  
  scale_y_continuous(breaks=seq(-10, 20, 5)) +
  
  scale_x_continuous(limits=c(-10,35), breaks=seq(-10, 30, 10)) +
  
  geom_vline(xintercept = 0, color="black", size=1) +
  
  geom_hline(yintercept = 0, color="black", size=1) +
  
  # annotate(geom = "text", 
  #          x = 3000, y = 20, 
  #          label = "x = 0",
  #          color="black",
  #          hjust = "left") +
  
  labs(x = "Différence du pourcentage de personnes \nayant accès à l'eau potable \nentre 2018 et 2000",
       y = "Différence d'espérance de vie \nentre 2018 et 2000",
       colour = "Espérance de vie \nen 2000",
       size = "% de personnes \nayant accès à l'eau \npotable en 2000") +
  
  ggtitle("Représentation de la relation entre \nles différences d'espérance de vie et \n de pourcentage de personnes ayant accès \nà l'eau potable entre 2018 et 2000") +
  
  theme(plot.title = element_text(face="bold", hjust=0.5, size=12), 
        axis.title.x = element_text(size=11),
        axis.title.y = element_text(size=11),
        panel.background = element_rect(fill = "white"),
        panel.grid.major = element_line(colour = "#CCCCCC"),
        plot.margin = unit(c(0,0,0,0), "cm"))
g4
```


Focus sur 3 pays
=======================================================================

Row
-----------------------------------------------------------------------

### Syrie

```{r}
dta$Life.expectancy<-round(dta$Life.expectancy,2)
m <- list(l = 50, r = 50, b = 10, t = 70, pad = 4)

dta_SYR <- subset(dta, ISO3 == "SYR")

old.y <- list(
  side = "left",
  range=c(69,75)
)

new.y <- list(
  overlaying = "y",
  side = "right",
  title ="Dépenses en santé (en % du GDP)",
  range=c(2.5,5.5),
  showgrid=F
)

fig1 <- plot_ly(dta_SYR) %>%
  
  add_lines(x = ~Year, y = ~Life.expectancy, yaxis="y1", name="Espérance de vie", 
            line = list(color = 'black', width = 3)) %>%
  
  add_lines(x = ~Year, y = ~Depense, yaxis = "y2", name="Dépenses en santé \n% du GDP",
            line = list(color = '#00AFBB', width = 2)) %>%
  
  layout(yaxis2 = new.y, font=list(size=10),
         
         yaxis = list(old.y, showgrid = T, title="Espérance de vie moyenne à \n la naissance (en années)"), 
         
         xaxis = list(title="Années", showgrid = F),
         
         legend = list(title=list(text=''), y = 73,
                       textfont = list(family = "Arial", size = 14, color = toRGB("black"))),
         
         title = list(text = paste0("Evolution de l'espérance de vie de la Syrie", '<br>',
                                    '<sup>', "entre 2018 et 2000"),
                      xanchor = 'left', x=0.1, font=list(size=16)),
         
         shapes = list(
           list(type = "rect",
                fillcolor = "#009EFF", line = list(color = "lightblue"), opacity = 0.2,
                x0 = "11", x1 = "18",
                y0 = 68.5, y1 = 75)), margin=m) %>%
  
  add_annotations(x = 14.5, y = 74.5, 
                  text  = "Guerre civile depuis 2011", 
                  xanchor = 'center',
                  showarrow = F) %>%
  add_annotations(x = 11, y = 69, 
                  text  = "Chute du GDP entre 2010 et 2012 : \n5,5 fois plus faible", 
                  xanchor = 'center',
                  showarrow = F)
fig1
```

### Grenade

```{r}
dta_off$Life.expectancy<-round(dta_off$Life.expectancy,2)
m <- list(l = 50, r = 50, b = 10, t = 70, pad = 4)

vline <- function(x = 0, color = "green") {
  list(
    type = "line",
    y0 = 0,
    y1 = 1,
    yref = "paper",
    x0 = x,
    x1 = x,
    line = list(color = color, dash="dot")
  )
}

fig2 <- plot_ly(dta_off[dta_off$ISO3 == "GRD",]) %>%
  
  add_lines(x = ~Year, y = ~Life.expectancy, line = list(color = 'black', width = 3)) %>%
  
  layout(xaxis = list(title="Années", showgrid = F), font=list(size=10),
         
         yaxis = list(title="Espérance de vie moyenne à \n la naissance (en années)", font=list(size=10)),
         
         legend = list(title=list(text=''), y = 73,
                       textfont = list(family = "Arial", size = 14, color = toRGB("black"))),
         
         title = list(text = paste0("Evolution de l'espérance de vie de Grenade", '<br>',
                                    '<sup>', "entre 2018 et 2000"),
                      xanchor = 'left', x=0.1, font=list(size=16)),
         
         # shapes = list(
         #   list(vline("4"), vline("5", col="#00AFBB")))
         
         shapes = list(vline("4",col="black"), vline("5",col="#00AFBB")), margin=m) %>%
  
  add_text(showlegend = FALSE, 
           x = c("2002","2007"), y = c(73.16, 73.16),
           text = c("Ouragan Ivan","Ouragan Emily"),
           textfont = list(family = "Arial", size = 14, color = list("black","#00AFBB")))
fig2
```



Row
-----------------------------------------------------------------------

### Venezuela

```{r, warning=F}
m <- list(l = 50, r = 50, b = 10, t = 70, pad = 4)

GDP_VEN <- read.csv("GDP_VEN.csv", sep=";")
colnames(GDP_VEN) <- c("2000", "2001", "2002","2003", "2004", "2005","2006", "2007", "2008","2009","2010", "2011", "2012","2013", "2014", "2015","2016","2017","2018")
GDP_VEN <- GDP_VEN %>% 
  pivot_longer(c("2000", "2001", "2002","2003", "2004", "2005","2006", "2007", "2008","2009","2010", "2011", "2012","2013", "2014", "2015","2016","2017","2018"))
colnames(GDP_VEN)[1:2] <- c("Year", "GDP")
GDP_VEN$Year <- as.factor(GDP_VEN$Year)
GDP_VEN$GDP_obs <- c(GDP_VEN$GDP[1:15], rep(NA,4))
GDP_VEN$GDP_pred <- c(rep(NA,14),GDP_VEN$GDP[15:19])
dta_dual_y <- data.frame(dta_off[dta_off$ISO3 == "VEN",])
dta_dual_y$GDP_obs <- c(GDP_VEN$GDP[1:15], rep(NA,4))
dta_dual_y$GDP_pred <- c(rep(NA,14),GDP_VEN$GDP[15:19])
dta_dual_y$Life.expectancy<-round(dta_dual_y$Life.expectancy,2)

old.y <- list(
  side = "left"
)

new.y <- list(
  overlaying = "y",
  side = "right",
  title = "GDP par habitant (USD)"
)

fig3 <- plot_ly(dta_dual_y) %>%
  
  add_lines(x = ~Year, y = ~Life.expectancy, yaxis="y1", name="Espérance de vie", 
            line = list(color = 'black', width = 3)) %>%
  
  add_lines(x = ~Year, y = ~GDP_obs, yaxis = "y2", name="GDP (données officielles)",
            line = list(color = '#00AFBB', width = 2)) %>%
  
  add_lines(x = ~Year, y = ~GDP_pred, yaxis = "y2", name="GDP (données estimées)",
            line = list(color = '#00AFBB', width = 2, dash = 'dot')) %>%
  
  layout(yaxis2 = new.y,font=list(size=10),
         
         yaxis = list(old.y, showgrid = F, title="Espérance de vie moyenne à \n la naissance (en années)"), 
         
         xaxis = list(title="Années", showgrid = F),
         
         legend = list(title=list(text=''), y = 73,
                       textfont = list(family = "Arial", size = 14, color = toRGB("black"))),
         
         title = list(text = paste0("Evolution de l'espérance de vie du Venezuela", '<br>',
                                    '<sup>', "entre 2018 et 2000"),
                      xanchor = 'left', x=0.1, font=list(size=16)),
         
         shapes = list(
           list(type = "rect",
                fillcolor = "lightblue", line = list(color = "lightblue"), opacity = 0.2,
                x0 = "0", x1 = "13",
                y0 = 72, y1 = 73.5),
           list(type = "rect",
                fillcolor = "#009EFF", line = list(color = "#009EFF"), opacity = 0.2,
                x0 = "13", x1 = "18",
                y0 = 72, y1 = 73.5)), margin=m) %>%
  
  add_text(showlegend = FALSE, 
           x = c("2006","2016"), y = c(73.25, 73.25),
           text = c("Présidence d'Hugo Chávez","Présidence de \nNicolás Maduro"),
           textfont = list(family = "Arial", size = 11, color = toRGB("black")))
fig3
```

###

```{r}

```